#include<bits/stdc++.h>
using namespace std;
const int num=2e5+1;
int n,t;
int a[num];
int c[num];

int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>t;
	while(t--){
		int ans=0;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		memset(c,0,sizeof(0));
		for(int i=2;i<=n;i++){
			if(i-2>=a[i-1]){
				if(a[i]==a[i-1]||a[i]-a[i-1]==1||a[i]==1||a[i]+a[i-1]<=i-2) c[i]=a[i];
			}
		}
		for(int i=1;i<=n;i++) ans+=c[i];
		cout<<ans<<endl;
	}
	return 0;
}
